Skip to content

fix(discord): reset hard bot turn counter on human message + extract BotTurnTracker with tests#473

Merged
thepagent merged 1 commit intoopenabdev:mainfrom
chaodu-agent:feat/hard-limit-human-reset
Apr 19, 2026
Merged

fix(discord): reset hard bot turn counter on human message + extract BotTurnTracker with tests#473
thepagent merged 1 commit intoopenabdev:mainfrom
chaodu-agent:feat/hard-limit-human-reset

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

@chaodu-agent chaodu-agent commented Apr 19, 2026

Summary

Builds on #467.

Human intervention should reset both soft and hard bot turn counters. Previously the hard counter never reset, meaning a thread could be permanently locked out of bot-to-bot conversation — even with active human oversight.

Also extracts BotTurnTracker struct for testability.

Changes

Behavior fix

  • Human message now resets both soft and hard counters to 0
Event Soft counter Hard counter
Bot message +1 +1
Soft limit hit (20) ⚠️ stop unchanged
Hard limit hit (100) 🛑 stop 🛑 stop
Human message reset to 0 reset to 0

Refactor: BotTurnTracker

Extracted inline counter logic into a testable struct:

pub(crate) struct BotTurnTracker { ... }

impl BotTurnTracker {
    pub fn new(soft_limit: u32) -> Self
    pub fn on_bot_message(&mut self, thread_id: &str) -> TurnResult
    pub fn on_human_message(&mut self, thread_id: &str)
}

enum TurnResult { Ok, SoftLimit(u32), HardLimit }

Unit tests (8 tests)

  • bot_turns_increment — basic counting
  • soft_limit_triggers — fires at exactly soft limit
  • human_resets_both_counters — soft + hard reset, can continue
  • hard_limit_triggers — fires at exactly hard limit
  • hard_limit_resets_on_human — human unlocks hard-limited thread
  • hard_before_soft_when_equal — when soft == hard limit, hard wins
  • threads_are_independent — different threads have separate counters
  • human_on_unknown_thread_is_noop — no panic on unknown thread

@chaodu-agent chaodu-agent requested a review from thepagent as a code owner April 19, 2026 14:27
@github-actions
Copy link
Copy Markdown

⚠️ This PR is missing a Discord Discussion URL in the body.

All PRs must reference a prior Discord discussion to ensure community alignment before implementation.

Please edit the PR description to include a link like:

Discord Discussion URL: https://discord.com/channels/...

This PR will be automatically closed in 3 days if the link is not added.

@github-actions github-actions bot added the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label Apr 19, 2026
@chaodu-agent chaodu-agent force-pushed the feat/hard-limit-human-reset branch from b3d013c to 5fc8381 Compare April 19, 2026 14:29
Human intervention should reset both soft and hard counters.
Previously hard counter never reset, meaning a thread could be
permanently locked out of bot-to-bot conversation even with
human oversight.

Extract BotTurnTracker struct for testability:
- on_bot_message() returns TurnResult::{Ok, SoftLimit, HardLimit}
- on_human_message() resets both counters
- 8 unit tests covering all edge cases

Builds on openabdev#467
@chaodu-agent chaodu-agent force-pushed the feat/hard-limit-human-reset branch from 5fc8381 to 7f2fc2c Compare April 19, 2026 14:32
@chaodu-agent chaodu-agent changed the title fix(discord): reset hard bot turn counter on human message fix(discord): reset hard bot turn counter on human message + extract BotTurnTracker with tests Apr 19, 2026
@thepagent thepagent merged commit 2ed0ada into openabdev:main Apr 19, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closing-soon PR missing Discord Discussion URL — will auto-close in 3 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants